package com.mini.service.impl;

import cn.hutool.core.date.DateUtil;
import com.mini.domain.entity.Msg;
import com.mini.exception.ServiceException;
import com.mini.mapper.MsgMapper;
import com.mini.service.IMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MsgServiceImpl implements IMsgService {

    @Autowired
    private MsgMapper mapper;

    @Override
    public int insert(Msg msg) {
        return mapper.insert(msg);
    }

    @Override
    public Long create(String channel, String content) {

        Msg msg = new Msg().setChannel(channel)
                .setContent(content);

        msg.setCreateTime(DateUtil.date());

        int insert = this.insert(msg);

        if (insert == 0) {
            throw new ServiceException("insert msg tabel info fail");
        }
        return msg.getId();
    }

}
